﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.Sql;
using System.Data.SqlClient;
using System.Collections;
using GPCSC.Web;

namespace GPCSC.Web.WBWZ
{
    public partial class xinxiSelect : PageBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                try
                {
                    buildTZGG();
                    buildGZJB();
                    string sd = Usual.f_querystringToString("dw");
                    if (sd != null )
                    {
                        string sdd = Usual.f_querystringToString("ld");
                        string sdg = Usual.f_querystringToString("xs");
                        select(sd, sdd, sdg);
                    }
                    else
                    {
                        select("","","");
                    }
                }
                catch (Exception ee)
                {
                    throw ee;
                }
            }
        }
        //绑定通知公告
        protected void buildTZGG()
        {
            Hashtable htable = new Hashtable();

            htable.Add("BTSBLMName", "2");
            DataSet ds = new DataReturn().ReturnData(htable, "sel_sydtxw_all");
            if (ds != null)
            {

                tzgg.DataSource = cutTitle(ds);
                tzgg.DataBind();
            }
        }
        //绑定工作简报
        protected void buildGZJB()
        {
            //Hashtable htable = new Hashtable();

            //htable.Add("BTSBLMName", "5");
            //DataSet ds = new DataReturn().ReturnData(htable, "sel_sydtxw_all");
            //if (ds != null)
            //{

            //    gzjb.DataSource = cutTitle(ds);
            //    gzjb.DataBind();

            //}
             Hashtable htable = new Hashtable();
            DataSet ds = new DataReturn().ReturnData(htable, "sel_mqlists_to");
            if (ds != null)
            {
                foreach (DataRow dr in ds.Tables[0].Rows)
                {
                    dr["NewsID"] = dr["tabids"].ToString();
                    dr["NewsTitles"] = Usual.f_convertDateTime(dr["mqdate"].ToString()).ToShortDateString() + " " + dr["lgname"].ToString() + "民情日记";
                    dr["showtitle"] = Usual.f_convertDateTime(dr["mqdate"].ToString()).ToShortDateString() + " " + dr["lgname"].ToString() + "民情日记";
                    dr["FBdate"] = Usual.f_convertDateTime(dr["mqdate"].ToString()).ToShortDateString();
                    dr["BTSBLMName"] = "6";
                }
                gzjb.DataSource = ds;
                gzjb.DataBind();
            }
        }
        /// <summary>
        /// 若标题过长  截取标题
        /// </summary>
        /// <param name="ds"></param>
        /// <returns></returns>
        protected DataSet cutTitle(DataSet ds)
        {
            if (ds.Tables[0].Rows.Count > 0)
            {
                foreach (DataRow dr in ds.Tables[0].Rows)
                {
                    if (dr["NewsTitles"].ToString().Length > 16)
                    {
                        dr["showtitle"] = dr["NewsTitles"].ToString().Substring(0, 16) + "...";
                    }
                    else
                    {
                        dr["showtitle"] = dr["NewsTitles"].ToString();
                    }
                }
            }
            return ds;
        }

        protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
        {
           
        }
        protected void select(string dw ,string ld,string xqs)
        {
            string sql = " where 1=1";
            if (ld != "")
            {
                sql += " and lgname like '%" + ld.Trim() + "%'";
            }
            if (dw != "")
            {
                sql += " and lgdw like '%" + dw.Trim() + "%'";
            }
            if (xqs != "")
            {
                sql += " and ggname like '%" + xqs.Trim() + "%'";
            }
            string sqls = new NotHTML().NoHTML(new SqlReadXml().SqlBack("sel_xqs_all"));

            sql = sqls + sql;
            //Hashtable htable = new Hashtable();
            //htable.Add("@SQLS",sql);
            DataSet ds = Maticsoft.DBUtility.DbHelperSQL.Query(sql);
            if (ds.Tables[0].Rows.Count > 0)
            {
                foreach (DataRow dr in ds.Tables[0].Rows)
                {
                    if (dr["ggvalue"].ToString() == "1")
                    {
                        dr["FBdate"] = "农村";
                    }
                    else if (dr["ggvalue"].ToString() == "3")
                    {
                        dr["FBdate"] = "社区";
                    }
                    else if (dr["ggvalue"].ToString() == "2")
                    {
                        dr["FBdate"] = "企业";
                    }

                }
                newslist.DataSource = ds;
                newslist.DataBind();

                this.pageinfo.InnerHtml = new FYpage().GetPageNum(ds.Tables[0], newslist, 15);
            }
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            //string sd = this.dw.Value;
            //string ld = this.mand.Value;
            //string xqs = this.xqs.Value;
            //select(sd, ld, xqs);
        }
    }
}